package com.digitalchina.lxnsy.activity.old;

import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.Constant;
import com.digitalchina.lxnsy.fragment.OrderFragment;
import com.kekstudio.dachshundtablayout.DachshundTabLayout;
import com.kekstudio.dachshundtablayout.indicators.LineMoveIndicator;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2017/8/7 16:03
 * 修改备注：
 * ================================================
 */
public class MyOrderListActivity extends BaseActivity {
    @Bind(R.id.tab_layout)
    DachshundTabLayout tabLayout;
    @Bind(R.id.viewPager)
    ViewPager viewPager;

    private MyPagerAdapter adapter;
    private List<Fragment> fragments = new ArrayList<>();
    private String title[] = {"全部", "待支付", "待发货", "待收货", "待评价"};
    /**
     * 20 - "待发货"
     * 21 - "待收货"
     * 22 - "待评价"
     * 23 - "已关闭"
     * 29 - "待支付"
     */
    private String queryStatus[] = {"", Constant.ORDER_STATUS_POST_WAIT_PAYMENT, Constant.ORDER_STATUS_POST_WAIT_DELIVERY, Constant.ORDER_STATUS_POST_WAIT_RECEIVING, Constant.ORDER_STATUS_POST_WAIT_EVALUATE};

    @Override

    public void setLayout() {
        setContentLayout(R.layout.activity_order_list);
        setTitle("我的订单");
    }

    @Override
    public void initMember() {

        tabLayout.setAnimatedIndicator(new LineMoveIndicator(tabLayout));

        for (int i = 0; i < title.length; i++) {
            OrderFragment orderFragment = new OrderFragment();
            fragments.add(orderFragment);
            Bundle bundle = new Bundle();
            bundle.putString("queryStatus", queryStatus[i]);
            orderFragment.setArguments(bundle);
        }

        adapter = new MyPagerAdapter(getSupportFragmentManager());
        viewPager.setOffscreenPageLimit(title.length);
        viewPager.setAdapter(adapter);

        tabLayout.setupWithViewPager(viewPager);

    }

    @Override
    public void addListener() {

    }

    @Override
    public void setHandler() {

    }

    @Override
    public void callBack(Object object) {

    }

    @Override
    public void rightOnClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    private class MyPagerAdapter extends FragmentStatePagerAdapter {
        private MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return title[position];
        }

//        public void setFragmentList(List<Fragment> pList) {
//            this.fragments = pList;
//            notifyDataSetChanged();
//        }


//        @Override
//        public int getItemPosition(Object object) {
//            // 最简单解决 notifyDataSetChanged() 页面不刷新问题的方法
//            return POSITION_NONE;
//        }
    }
}
